package com.wicket.okrcalc.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrcalc.biz.service.dto.req.*;
import com.wicket.okrcalc.biz.service.dto.res.*;
import com.wicket.okrcalc.common.exception.BizException;
import com.wicket.okrcalc.common.util.CommonFunctionHelper;
import com.wicket.okrcalc.common.util.RedisUtil;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.wicket.okrapp.integration.dto.QueryEvaObjTargetCycleDetailComRespDto;
import com.wicket.okrapp.integration.dto.QueryEvaObjTargetCycleDetailComReqDto;
import com.wicket.okrapp.integration.dto.QueryTargetContentInfoDetailComRespDto;
import com.wicket.okrapp.integration.dto.QueryTargetContentInfoDetailComReqDto;
import com.wicket.okrapp.integration.dto.ImplementContentTypeChangeTableTypeComRespDto;
import com.wicket.okrapp.integration.dto.ImplementContentTypeChangeTableTypeComReqDto;
import com.wicket.okrapp.integration.dto.QueryCycleStageDataDetailComRespDto;
import com.wicket.okrapp.integration.dto.QueryCycleStageDataDetailComReqDto;
import com.wicket.okrcalc.common.exception.Assert;
import com.wicket.okrcalc.biz.service.nb.NbTargetContent;
import com.wicket.okrapp.integration.FwAppTargetCycleClient;
import com.wicket.okrapp.integration.FwAppTargetContentClient;
import com.wicket.okrapp.integration.FwAppIndexSystemClient;
import com.wicket.okrapp.integration.FwAppCycleStageDataClient;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class TargetContentServiceImpl
  implements com.wicket.okrcalc.biz.service.TargetContentService {

  @Resource
  private RedisUtil redisUtil;
//@Resource
 //private MCustomFieldsService mCustomFieldsService;
@Resource
  private NbTargetContent nbTargetContent;
@Resource
  private FwAppTargetCycleClient fwAppTargetCycleClient;
@Resource
  private FwAppTargetContentClient fwAppTargetContentClient;
@Resource
  private FwAppIndexSystemClient fwAppIndexSystemClient;
@Resource
  private FwAppCycleStageDataClient fwAppCycleStageDataClient;
//@Resource
 //private MCustomFields3Service mCustomFields3Service;
/**
   * D4-准备计算参照值目标内容（公共）[6000]
   * gen by moon at 6/23/2023, 5:36:05 AM
   */
  @Trace(operationName = "D4-准备计算参照值目标内容（公共）")
  @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Transactional(rollbackFor=Exception.class)
  @Override
  public QueryCalcReferenceContentDetailComRespDto queryCalcReferenceContentDetailCom(QueryCalcReferenceContentDetailComReqDto reqDto){
    
      
      QueryEvaObjTargetCycleDetailComRespDto queryEvaObjTargetCycleDetailComRespDto_1 =null;
QueryTargetContentInfoDetailComRespDto queryTargetContentInfoDetailComRespDto_1 =null;
ImplementContentTypeChangeTableTypeComRespDto implementContentTypeChangeTableTypeComRespDto_1 =null;
//步骤0: M4-执行接收字段（特殊方法） - implementReceiveField
     //ModelCode: receptionService
        ImplementReceiveFieldRespDto receptionServiceRes = null;
    ImplementReceiveFieldReqDto receptionServiceReq=new ImplementReceiveFieldReqDto();
  if(reqDto!=null){
      receptionServiceReq.setEvaObjTargetCycleId(reqDto.getEvaObjTargetCycleId());//SimpleFieldAssign//sourceId:714398_1
receptionServiceReq.setEvaluationTemplateId(reqDto.getEvaluationTemplateId());//SimpleFieldAssign//sourceId:714399_1
    }
  
    /*M4-执行接收字段（特殊方法）[2950]  用于特殊方法接收上游入参。 */
    Assert.isNull(receptionServiceReq.getEvaObjTargetCycleId(),"D4-准备计算参照值目标内容（公共）-M4-执行接收字段（特殊方法）-被评对象目标周期ID不能为空",false);
Assert.isNull(receptionServiceReq.getEvaluationTemplateId(),"D4-准备计算参照值目标内容（公共）-M4-执行接收字段（特殊方法）-冗余评价模板ID不能为空",false);
      receptionServiceRes = nbTargetContent.implementReceiveField(receptionServiceReq);
      
      
      
    
//步骤1: D3-3查询被评对象目标周期详情(公共) - queryEvaObjTargetCycleDetailCom
     QueryEvaObjTargetCycleDetailComRespDto queryEvaObjTargetCycleDetailComRespDto = null;
    QueryEvaObjTargetCycleDetailComReqDto queryEvaObjTargetCycleDetailComReqDto=new QueryEvaObjTargetCycleDetailComReqDto();
  queryEvaObjTargetCycleDetailComReqDto.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:714354_1
if(reqDto!=null){
      queryEvaObjTargetCycleDetailComReqDto.setEvaObjTargetCycleId(reqDto.getEvaObjTargetCycleId());//SimpleFieldAssign//sourceId:714352_1
queryEvaObjTargetCycleDetailComReqDto.setEvaluationTemplateId(reqDto.getEvaluationTemplateId());//SimpleFieldAssign//sourceId:714353_1
    }
  
    /*D3-3查目标周期详情（获内容信息）[3489]   */
    Assert.isNull(queryEvaObjTargetCycleDetailComReqDto.getEvaObjTargetCycleId(),"D4-准备计算参照值目标内容（公共）-D3-3查目标周期详情（获内容信息）-被评对象目标周期ID不能为空",false);
Assert.isNull(queryEvaObjTargetCycleDetailComReqDto.getEvaluationTemplateId(),"D4-准备计算参照值目标内容（公共）-D3-3查目标周期详情（获内容信息）-冗余评价模板ID不能为空",false);
Assert.isNull(queryEvaObjTargetCycleDetailComReqDto.getSubjectLifeCycle(),"D4-准备计算参照值目标内容（公共）-D3-3查目标周期详情（获内容信息）-主体生命周期不能为空",false);
      queryEvaObjTargetCycleDetailComRespDto = fwAppTargetCycleClient.queryEvaObjTargetCycleDetailCom(queryEvaObjTargetCycleDetailComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      queryEvaObjTargetCycleDetailComRespDto_1 = queryEvaObjTargetCycleDetailComRespDto;
    
//步骤2: D3-查询目标内容公共信息详情（公共） - queryTargetContentInfoDetailCom
     QueryTargetContentInfoDetailComRespDto queryTargetContentInfoDetailComRespDto = null;
    if(queryEvaObjTargetCycleDetailComRespDto !=null){
          QueryTargetContentInfoDetailComReqDto queryTargetContentInfoDetailComReqDto=new QueryTargetContentInfoDetailComReqDto();
  if(queryEvaObjTargetCycleDetailComRespDto!=null){
      queryTargetContentInfoDetailComReqDto.setTargetCycleContentId(queryEvaObjTargetCycleDetailComRespDto.getTargetCycleContentId());//SimpleFieldAssign//sourceId:714368_1
queryTargetContentInfoDetailComReqDto.setTargetCycleContentTypeCode(queryEvaObjTargetCycleDetailComRespDto.getTargetCycleContentTypeCode());//SimpleFieldAssign//sourceId:714367_1
    }
if(reqDto!=null){
      queryTargetContentInfoDetailComReqDto.setEvaluationTemplateId(reqDto.getEvaluationTemplateId());//SimpleFieldAssign//sourceId:714359_1
    }
  
    /*D3-查询目标内容公共信息详情（公共）[5924]   */
    Assert.isNull(queryTargetContentInfoDetailComReqDto.getTargetCycleContentId(),"D4-准备计算参照值目标内容（公共）-D3-查询目标内容公共信息详情（公共）-关联目标内容ID不能为空",false);
Assert.isNull(queryTargetContentInfoDetailComReqDto.getTargetCycleContentTypeCode(),"D4-准备计算参照值目标内容（公共）-D3-查询目标内容公共信息详情（公共）-关联目标内容类型编码不能为空",false);
Assert.isNull(queryTargetContentInfoDetailComReqDto.getEvaluationTemplateId(),"D4-准备计算参照值目标内容（公共）-D3-查询目标内容公共信息详情（公共）-冗余评价模板ID不能为空",false);
      queryTargetContentInfoDetailComRespDto = fwAppTargetContentClient.queryTargetContentInfoDetailCom(queryTargetContentInfoDetailComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      queryTargetContentInfoDetailComRespDto_1 = queryTargetContentInfoDetailComRespDto;
           }
    
//步骤3: D3执行内容类型互转表类型(公共) - implementContentTypeChangeTableTypeCom
     ImplementContentTypeChangeTableTypeComRespDto implementContentTypeChangeTableTypeComRespDto = null;
    if(queryEvaObjTargetCycleDetailComRespDto !=null){
          ImplementContentTypeChangeTableTypeComReqDto implementContentTypeChangeTableTypeComReqDto=new ImplementContentTypeChangeTableTypeComReqDto();
  if(queryEvaObjTargetCycleDetailComRespDto!=null){
      implementContentTypeChangeTableTypeComReqDto.setTargetCycleContentTypeCode(queryEvaObjTargetCycleDetailComRespDto.getTargetCycleContentTypeCode());//SimpleFieldAssign//sourceId:714376_1
    }
  
    /*D3执行内容类型互转表类型(公共)[5354]   */
    Assert.isNull(implementContentTypeChangeTableTypeComReqDto.getTargetCycleContentTypeCode(),"D4-准备计算参照值目标内容（公共）-D3执行内容类型互转表类型(公共)-关联目标内容类型编码不能为空",false);
      implementContentTypeChangeTableTypeComRespDto = fwAppIndexSystemClient.implementContentTypeChangeTableTypeCom(implementContentTypeChangeTableTypeComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;
      
      
      implementContentTypeChangeTableTypeComRespDto_1 = implementContentTypeChangeTableTypeComRespDto;
           }

QueryCalcReferenceContentDetailComRespDto retData = new QueryCalcReferenceContentDetailComRespDto();
  if(implementContentTypeChangeTableTypeComRespDto_1!=null){
      retData.setTableTypeCode(implementContentTypeChangeTableTypeComRespDto_1.getTableTypeCode());//SimpleFieldAssign//sourceId:714407_1
    }
if(queryEvaObjTargetCycleDetailComRespDto_1!=null){
      retData.setTargetCycleContentTypeCode(queryEvaObjTargetCycleDetailComRespDto_1.getTargetCycleContentTypeCode());//SimpleFieldAssign//sourceId:1042898_1
      retData.setTargetCycleContentId(queryEvaObjTargetCycleDetailComRespDto_1.getTargetCycleContentId());//SimpleFieldAssign//sourceId:714404_1
retData.setSpaceId(queryEvaObjTargetCycleDetailComRespDto_1.getSpaceId());//SimpleFieldAssign//sourceId:769592_1
retData.setEvaObjTargetCycleCode(queryEvaObjTargetCycleDetailComRespDto_1.getEvaObjTargetCycleCode());//SimpleFieldAssign//sourceId:825370_1
retData.setCycleStartTime(queryEvaObjTargetCycleDetailComRespDto_1.getCycleStartTime());//SimpleFieldAssign//sourceId:825371_1
    }
if(queryTargetContentInfoDetailComRespDto_1!=null){
      retData.setRootTargetCategoryId(queryTargetContentInfoDetailComRespDto_1.getRootTargetCategoryId());//SimpleFieldAssign//sourceId:714405_1
retData.setUnit(queryTargetContentInfoDetailComRespDto_1.getUnit());//SimpleFieldAssign//sourceId:714406_1
    }
  

  
  
return retData;
  }
  //
}
